package com.lnsf.bookstore.system.advPosition.controller;

import com.github.pagehelper.PageInfo;
import com.lnsf.bookstore.common.annotation.SysLog;
import com.lnsf.bookstore.common.dto.ResultSuccessDto;
import com.lnsf.bookstore.system.advPosition.service.AdvPositionService;
import com.lnsf.bookstore.system.advPosition.vo.AdvPosition;
import com.lnsf.bookstore.system.book.vo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/advposition")
public class AdvPositionController {


    @Autowired
    private AdvPositionService advPositionService;

    @RequestMapping("/v_list.do")
    public String list(){
        return "admin/adverise/advposition";
    }

    /**
     * 查看所有列表
     */
    @SysLog("查看广告位置列表")
    @RequestMapping("/queryAll")
    @ResponseBody
    public Object queryAll(@RequestParam Map<String, Object> params, AdvPosition advPosition) {
        PageInfo<AdvPosition> pageInfo = advPositionService.selectAll(params , advPosition);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page",pageInfo);
        return map;
    }

    /**
     * 修改、新增操作
     */
    @SysLog("修改/新增")
    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Object saveOrUpdate(HttpServletRequest request, Integer id , @RequestBody AdvPosition advPosition, ModelMap modelMap){
        if(advPosition.getId()==null){//新增
            //verifyForm(category);
            advPositionService.save(advPosition);
        }else{//修改
            //verifyForm(category);
            advPositionService.update(advPosition);
        }
        return new ResultSuccessDto("操作成功");
    }


    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    @SysLog("查看广告位置信息")
    public Object info(@PathVariable("id") Integer id) {
        AdvPosition advPosition = advPositionService.queryObject(id);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("advPosition",advPosition);
        return map;
    }
}
